package org.stvd.common.utils;

import java.io.Serializable;

/**
 * @Title: InterfaceResult
 * @Description 接口请求结果统一处理类
 * @author houzx
 * @date 2020年10月21日
 */
public class InterfaceResult<T> implements Serializable  {

    private static final long serialVersionUID = -155155513603840660L;

    /** 请求结果{0：默认成功}*/
    private String code = "0";
    
    /** 返回信息*/
    private String msg = "请求成功！";
    
    /** 返回数据*/
    private T result = null;
    
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
    
    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    /**
     * @Description: 设置错误信息
     * @param msg 错误信息
     */
    public void setError(String msg) {
        this.code = "1";
        this.msg = msg;
    }
    
    /**
     * @Description: 业务层封装转为接口层封装
     * @param serviceResult
     */
    public void transferResult(ServiceResult<T> serviceResult) {
        if(serviceResult!=null) {
            this.code = serviceResult.getCode();
            this.msg = serviceResult.getMessage();
            this.result = serviceResult.getResult();
        }
    }
    
}
